home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: Q:order of evaluation
- Date: 20 Jan 1996 05:49:44 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4dpvpo$qog@colossus.holonet.net>
- References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Jim Hamilton (hamilton@shokwave.com) wrote:
- : In article <4dfhlu$a33$1@mhafn.production.compuserve.com>, Holger Maier
- : <100336.3326@CompuServe.COM> wrote:
-
- : > int i=1;int j=i+(i+=1);
-
- : The highest precedence in any expression is the insides of parentheses
- : (). Therefore (i+=1) is evaluated before i+().
-
- Once again (sigh), "precedence" is not the same as "order of evaluation".
- Expressions do NOT have precedence; rather, operators do. The contents
- of parentheses are an expression, and therefore the word "precedence"
- does not apply to them. (BTW, see note below.)
-
- It is tempting to think of the contents of parens as "evaluated first",
- and the language might have been designed that way, but it was NOT.
- As others have already pointed out, the ARM explicitly states that the
- expression i, on the LHS of +, can be evaluated before or after the
- expression (i+=1) on the RHS. The result is therefore undefined.
-
- If you use the word "precedence" to say something about time, i.e. the
- order in which subexpressions are evaluated, you are WRONG. I know this
- seems odd, but you have to get out of the habit of thinking in time.
-
- --
-
- NOTE: it occurs to me that you may be confused by the () operator,
- which does have high precedence. But remember, parentheses have MANY
- uses in C++, only one of which is the () operator. The usage above,
- for grouping, is syntactically and semantically distinct. And BTW,
- even if we did have the () operator here, the notion of "precedence"
- would not apply to, as you say, "the insides" of the parentheses.
-
- Please ponder this a while before posting a too-hasty reply. Read
- what the ARM very precisely says about "order of evaluation" (not
- "precedence") and consider: quite possibly, you don't yet know the
- last word about C++.
- --
- Russell Blackadar, russell@mdli.com
-